#pragma once

#include "../base/types.h"
#include <openssl/aes.h>
#include <cstdint>

OPEN_JLIB_NS


struct AES {

  inline ~AES () noexcept {
    reset();
  }


  constexpr static uwl encrypt_size (uwl src_size) noexcept {
    return (src_size + AES_BLOCK_SIZE) & ~(AES_BLOCK_SIZE - 1);
  }

  constexpr static uwl decrypt_size (uwl src_size) noexcept {
    return src_size % AES_BLOCK_SIZE ? 0 : src_size;
  }


  bool setup (const void* key, s32 version) noexcept;

  void reset () noexcept;


  uwl encrypt (void* dst, const void* src, uwl src_size, u8 init_vec[AES_BLOCK_SIZE]) noexcept;

  swl decrypt (void* dst, const void* src, uwl src_size, u8 init_vec[AES_BLOCK_SIZE]) noexcept;


private:
  s32 _key_len {0};
  u8 _key_buf[32];
};


CLOSE_JLIB_NS